<% layout('/layouts/default.html', {title: '用户表管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('用户表管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('ic:icUser:edit')){ %>
<!--					<a href="${ctx}/ic/icUser/form" class="btn btn-default btnTool" title="${text('新增用户表')}"><i class="fa fa-plus"></i> ${text('新增')}</a>-->
				<% } %>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${icUser}" action="${ctx}/ic/icUser/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('手机号')}：</label>
					<div class="control-inline">
						<#form:input path="mobile" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm isQuick">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>

<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("昵称")}', name:'nicheng', index:'a.mobile', width:150, align:"left", formatter: function(val, obj, row, act){
			return val?val:"兼职宝宝";
		}},
		{header:'${text("头像")}', name:'avatarUrl', index:'a.mobile', width:150, align:"center", formatter: function(val, obj, row, act){
			return '<img src="'+val+'" style="width: 50px;height: 50px;"/>';
		}},
		{header:'${text("手机号")}', name:'mobile', index:'a.mobile', width:150, align:"left"},
		// {header:'${text("企业")}', name:'companyName', index:'a.mobile', width:150, align:"left"},
		{header:'${text("余额")}', name:'yue', index:'a.mobile', width:150, align:"left"},
		// {header:'${text("卡数量")}', name:'cardNum', index:'a.mobile', width:150, align:"left"},
		{header:'${text("注册时间")}', name:'createTime',  width:150, align:"center"},
		{header:'${text("最近一次登录时间")}', name:'loginTime', index:'a.login_time', width:150, align:"center"},
		{header:'${text("未登录天数")}', name:'weidenglvDay',  width:150, align:"center"},
		// {header:'${text("最近下单时间")}', name:'orderTime', index:'a.login_time', width:150, align:"center"},
		// {header:'${text("距上次下单间隔天数")}', name:'orderDayNum', index:'a.login_time', width:150, align:"center"},
		{header:'${text("分销人数")}', name:'xiajiNum', index:'a.login_time', width:150, align:"center"},
		{header:'${text("设备数量")}', name:'deviceNum', width:150, align:"center"},
		{header:'${text("分销设备数")}', name:'fenxiaoDevice', index:'a.login_time', width:150, align:"center"},
		{header:'${text("设备抽成比例（%）")}', name:'agentRatio', index:'a.login_time', width:150, align:"center"},
		{header:'${text("版本")}', name:'appVersion',  width:150, align:"center"},
		{header:'${text("应用类型")}', name:'appDeviceType',  width:150, align:"center", formatter: function(val, obj, row, act){
			if (val == 1) {
				return '安卓';
			} else if (val == 2) {
				return 'H5';
			}
			return '';
		}},
		{header:'${text("是否媒体")}', name:'appVersion',  width:150, align:"center", formatter: function(val, obj, row, act){
				if (row.isMeiti == 0) {
					return '<a href="${ctx}/ic/icUser/meitiUser?id=' + row.id + '&isMeiti=1" class="btnList switchSkin" style="font-size: 30px" title="${text("普通用户")}" data-confirm="${text("确认要升级为媒体用户吗？")}"><i class="fa fa-toggle-off"></i></a>';
				} else if (row.isMeiti == 1) {
					return '<a href="${ctx}/ic/icUser/meitiUser?id=' + row.id + '&isMeiti=0" class="btnList switchSkin" style="font-size: 30px" title="${text("媒体用户")}" data-confirm="${text("确认要降级为普通用户吗？")}"><i class="fa fa-toggle-on"></i></a>';
				}
		}},
		{header:'${text("上级")}', name:'', index:'a.login_time', width:150, align:"center", formatter: function(val, obj, row, act){
			if(row.parentUser){
				return row.parentUser.nicheng ? row.parentUser.nicheng: row.parentUser.mobile;
			}else{
				return "";
			}
		}},
		// {header:'${text("注册时间")}', name:'createTime', index:'a.create_time', width:150, align:"center"},
		// {header:'${text("用户类型 1主用户 2协作人")}', name:'userType', index:'a.user_type', width:150, align:"left"},
		{header:'${text("操作")}', name:'actions', width:220, formatter: function(val, obj, row, act){
			var actions = [];
				// actions.push('<a href="${ctx}/ic/icUser/form?id='+row.id+'" class="btnList" title="${text("编辑")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				// actions.push('<a href="javascript:;" class="" onclick="bindDevice(\''+row.id+'\')">绑设备</a>&nbsp;');
				actions.push('<a href="javascript:;" class="" onclick="deviceList(\''+row.id+'\')">设备分销</a>&nbsp;');
				actions.push('<a href="javascript:;" class="" onclick="userList(\''+row.id+'\')">下级用户</a>&nbsp;');
				actions.push('<a href="javascript:;" class="" onclick="fenchengSet(\''+row.id+'\')">设置分成</a>&nbsp;');
				// if (row.status == Global.STATUS_NORMAL){
				// 	actions.push('<a href="${ctx}/ic/icUser/disable?id='+row.id+'" class="btnList" title="${text("停用用户表")}" data-confirm="${text("确认要停用该用户表吗？")}"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
				// } else if (row.status == Global.STATUS_DISABLE){
				// 	actions.push('<a href="${ctx}/ic/icUser/enable?id='+row.id+'" class="btnList" title="${text("启用用户表")}" data-confirm="${text("确认要启用该用户表吗？")}"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
				// }

				// actions.push('<a href="${ctx}/ic/icUser/delete?id='+row.id+'" class="btnList" title="${text("删除用户表")}" data-confirm="${text("确认要删除该用户表吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>

<script>

	function fenchengSet(id){
		js.layer.open({
			type: 2,
			title: '设置',
			shadeClose: true,
			shade: false,
			maxmin: true, //开启最大化最小化按钮
			area: ['60%', '300px'],
			content: "${ctx}/ic/icUser/set?id="+id
		});
	}

	function deviceList(id){
		js.layer.open({
			type: 2,
			title: '绑定的设备',
			shadeClose: true,
			shade: false,
			maxmin: true, //开启最大化最小化按钮
			area: ['80%', '700px'],
			content: "${ctx}/rt/rtDevice/daililist?dailishangId="+id
		});
	}

	function userList(id){
		js.layer.open({
			type: 2,
			title: '绑定的设备',
			shadeClose: true,
			shade: false,
			maxmin: true, //开启最大化最小化按钮
			area: ['80%', '700px'],
			content: "${ctx}/ic/icUser/list?parentUserId="+id
		});
	}
</script>